package com.nbufe.controller;

import com.nbufe.common.core.domain.R;
import com.nbufe.domain.ResponseResult;
import com.nbufe.domain.entity.IndustoryProduce;
import com.nbufe.domain.form.*;
import com.nbufe.domain.vo.industry.AddYearMonthSolventVo;
import com.nbufe.domain.vo.industry.YearMonthSolventCo2Vo;
import com.nbufe.service.IndustoryProduceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LZH
 * @date 2023/4/1
 */
@CrossOrigin
@Api(tags = "工业生产模块CO2排放")
@RestController
@RequestMapping("/industryProduce")
public class IndustryProduceController {

    @Resource
    private IndustoryProduceService industoryProduceService;

    @ApiOperation("计算指定年指定月指定材料的碳排放量")
    @PutMapping("/targetYearMonthSolventCo2")
    public R calTargetYearMonthSolventCo2(@RequestBody YearMonthSolventCo2Vo vo) {
        return industoryProduceService.calTargetYearMonthSolventCo2(vo);
    }

    @ApiOperation("添加指定年指定月指定材料的消耗信息")
    @PutMapping("/addTargetYearMonthSolvent")
    public R addTargetYearMonthSolvent(@RequestBody AddYearMonthSolventVo vo) {
        return industoryProduceService.addTargetYearMonthSolvent(vo);
    }

    @ApiOperation("查询指定年指定月指定材料的碳排放")
    @GetMapping("/{materialId}")
    public R getTargetYearMonthMaterial(@PathVariable Integer materialId) {
        IndustoryProduce industoryProduce = industoryProduceService.getById(materialId);
        return R.ok(industoryProduce.getCarbonEmission());
    }

    @ApiOperation("查询指定年指定月的所有材料的碳排放")
    @GetMapping("/queryMaterial/{year}/{month}")
    public R queryAllMaterialCarbonByMonth(@PathVariable Integer year,
                                           @PathVariable Integer month) {
        Double emission = industoryProduceService.queryAllMaterialCarbonByMonth(year, month);
        return R.ok(emission);
    }

    @ApiOperation("查询指定年所有材料的碳排放")
    @GetMapping("/queryAllMaterial/{year}")
    public R queryAllMaterialByYear(@PathVariable Integer year) {
        Double emission = industoryProduceService.queryAllMaterialCarbonByYear(year);
        return R.ok(emission);
    }

    @ApiOperation("查询指定年指定材料的碳排放")
    @GetMapping("/queryTargetMaterialByYear/{materialId}/{year}")
    public R queryTargetMaterialByYear(@PathVariable Integer materialId,
                                       @PathVariable Integer year) {
        Double emission = industoryProduceService.queryTargetYearMaterialCo2(materialId, year);
        return R.ok(emission);
    }


    @ApiOperation("分页条件查询固碳产品信息")
    @PostMapping("/pageList")
    public ResponseResult pageList(@RequestBody QueryIndustryProduceForm form) {
        return industoryProduceService.pageList(form);
    }

    @ApiOperation("获取所有工业生产的材料")
    @GetMapping("/list")
    public ResponseResult listAllIndustryProduceMaterial() {
        return industoryProduceService.listAllIndustryProduceMaterial();
    }

    @ApiOperation("获取所有存在的年份")
    @GetMapping("/years")
    public ResponseResult listYears() {
        List<Integer> years = industoryProduceService.listYears();
        return ResponseResult.okResult(years);
    }

    @ApiOperation("批量/单个删除固碳产品信息")
    @DeleteMapping("/delete")
    public ResponseResult deleteIndustryProduce(@RequestBody List<Integer> ids) {
        return industoryProduceService.deleteOneOrBatch(ids);
    }

    @ApiOperation("添加工业材料消耗信息")
    @PostMapping("/add")
    public ResponseResult addElectricHeat(@RequestBody AddIndustoryProduceForm form) {
        return industoryProduceService.addIndustoryProduce(form);
    }

    @ApiOperation("修改工业材料消耗信息")
    @PutMapping("/modify")
    public ResponseResult modifyFossiFuelInfo(@RequestBody ModifyIndustoryProduceForm form) {
        return industoryProduceService.modifyIndustoryProduceInfo(form);
    }
}
